﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsApp1.Common;
using WinFormsApp1.Leo;

namespace WinFormsApp1.SuYi.Week2WinForm
{
    public partial class WaitingWinForm : Form
    {
        public WaitingWinForm()
        {
            InitializeComponent();
            GetSrction();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void WaitingWinForm_Load(object sender, EventArgs e)
        {

        }
        private async void button1_Click(object sender, EventArgs e)
        {
          
        }

        //部门
        public async void GetSrction()
        {

            var items = await HttpClientHelper.RequestUrl<string, ApiResult<List<Sectionstes>>>(URLCommon.Url2, "/Week01Get/ShowSectionData1", HttpClientHelper.MethodType.GET, default);

            uiComboBox1SectionId.DataSource = items.Data;
            uiComboBox1SectionId.DisplayMember = "businessName";
            uiComboBox1SectionId.ValueMember = "businessId";

            this.Controls.Add(uiComboBox1SectionId);
        }



        /// <summary>
        /// 待宰圈设置字段
        /// </summary>
        public class Waitings
        {
            /// <summary>
            /// 待宰圈编号
            /// </summary>
            [Key]
            public int WaitingId { get; set; }
            /// <summary>
            /// 待宰圈名称
            /// </summary>
            public string WaitingName { get; set; }
            /// <summary>
            /// 待宰圈类型
            /// </summary>
            public string WaitingType { get; set; }
            /// <summary>
            /// 顺序号
            /// </summary>
            public string WaitingNo { get; set; }
            /// <summary>
            /// 使用状态
            /// </summary>
            public bool WaitingStatu { get; set; }
            /// <summary>
            /// 备注
            /// </summary>
            public string WaitingRemark { get; set; }
            /// <summary>
            /// 部门编号
            /// </summary>
            public int SectionId { get; set; }
            /// <summary>
            /// 负责人
            /// </summary>
            public string WaitingDuty { get; set; }
            /// <summary>
            /// 逻辑删除
            /// </summary>
            public int IsDel { get; set; }
        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void comboBox1SectionId_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 提交按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void uiButton1_Click(object sender, EventArgs e)
        {
            var waitingName = uiTextBox2Name.Text;
            var waitingType = uiRadioButton1Type.Checked && uiRadioButton2Type.Checked ? "自营待宰圈" : "代宰待宰圈";
            var waitingNo = uiTextBox1WaitingNo.Text;
            var waitingRemark = uiTextBox4Remark.Text;
            var sectionId = Convert.ToInt32(uiComboBox1SectionId.SelectedValue);
            var waitingDuty = uiTextBox4Remark.Text;




            Waitings waitings = new Waitings()
            {
                WaitingName = waitingName,
                WaitingType = waitingType,
                WaitingNo = waitingNo,
                WaitingStatu = false,
                WaitingRemark = waitingRemark,
                WaitingDuty = waitingDuty,
                SectionId = sectionId,
                IsDel = 0
            };

            var list = await HttpClientHelper.RequestUrl<Waitings, ApiResult<Waitings>>(URLCommon.Url1, "/Week2Setup/AddWaiting", HttpClientHelper.MethodType.POST, waitings);
            if (list.Code == 1)
            {
                MessageBox.Show("添加成功");
            }
            else
            {
                MessageBox.Show("添加失败");
            }
        }
    }
}
